package com.fdb.efp.nls.service.impl;

import com.fdb.efp.nls.service.domain.NlsStageInfo;
import com.fdb.efp.nls.service.facade.NlsStageInfoService;
import com.fdb.efp.nls.service.vo.NlsStageInfoVO;
import com.fdb.basic.framework.core.base.FrameworkService;
import com.fdb.efp.nls.service.dao.NlsStageInfoDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Service Impl: nls阶段开关表服务实现
 *
 * @author gcb
 * @date 2020-08-27
 */
@Service("nlsStageInfoService")
public class NlsStageInfoServiceImpl implements NlsStageInfoService, FrameworkService {

    private static Logger logger = LoggerFactory.getLogger(NlsStageInfoServiceImpl.class);

    @Autowired
    private NlsStageInfoDao nlsStageInfoDao;

    /**
     * 新增数据
     *
     * @param nlsStageInfoVo
     * @return
     */
    @Override
    public int insert(NlsStageInfoVO nlsStageInfoVo) throws Exception {
        NlsStageInfo nlsStageInfo = new NlsStageInfo();
        beanCopy(nlsStageInfoVo, nlsStageInfo);
        return nlsStageInfoDao.insert(nlsStageInfo);
    }

    /**
     * 根据主键删除信息
     *
     * @param nlsStageInfoVo
     * @return
     */
    @Override
    public int deleteByPk(NlsStageInfoVO nlsStageInfoVo) throws Exception {
        NlsStageInfo nlsStageInfo = new NlsStageInfo();
        beanCopy(nlsStageInfoVo, nlsStageInfo);
        return nlsStageInfoDao.deleteByPk(nlsStageInfo);
    }

    /**
     * 根据主键更新信息
     *
     * @param nlsStageInfoVo
     * @return
     */
    @Override
    public int updateByPk(NlsStageInfoVO nlsStageInfoVo) throws Exception {
        NlsStageInfo nlsStageInfo = new NlsStageInfo();
        beanCopy(nlsStageInfoVo, nlsStageInfo);
        return nlsStageInfoDao.updateByPk(nlsStageInfo);
    }

    /**
     * 根据主键查询详情
     *
     * @param inNlsStageInfoVo
     * @return
     */
    @Override
    public NlsStageInfoVO queryByPk(NlsStageInfoVO inNlsStageInfoVo) throws Exception {
        NlsStageInfo queryNlsStageInfo = new NlsStageInfo();
        beanCopy(inNlsStageInfoVo, queryNlsStageInfo);
        NlsStageInfo queryRslNlsStageInfo = nlsStageInfoDao.queryByPk(queryNlsStageInfo);
        return beanCopy(queryRslNlsStageInfo, new NlsStageInfoVO());
    }

    @Override
    public List<NlsStageInfoVO> queryList() throws Exception {
        List<NlsStageInfo> list = nlsStageInfoDao.queryList();
        List<NlsStageInfoVO> infoVOS = new ArrayList<>();
        for(NlsStageInfo info:list){
            NlsStageInfoVO vo = new NlsStageInfoVO();
            beanCopy(info,vo);
            infoVOS.add(vo);
        }
        return infoVOS;
    }
}
